//
//  DownLoadData.m
//  007AFN的使用
//
//  Created by 黎跃春 on 15/5/18.
//  Copyright (c) 2015年 黎跃春. All rights reserved.
//

#import "DownLoadData.h"
#import "AFAppDotNetAPIClient.h"
//#import "User.h"
@implementation DownLoadData
//发送微博不带图片
//https://api.weibo.com/2/statuses/update.json
+ (NSURLSessionDataTask *)sendWeiboWithBlock:(void (^)(id obj, NSError *error))block andContent:(NSString*)content {

    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:ACCESS_TOKEN];
    
    NSDictionary *params = @{@"access_token":token,@"status":content};
    
    return [[AFAppDotNetAPIClient sharedClient] POST:@"2/statuses/update.json" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (block) {
            block(responseObject,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"%@",error);
        if (block) {
            block(nil,error);
        }
    }];


}

//发送微博带图片
//https://api.weibo.com/2/statuses/upload.json
+ (NSURLSessionDataTask *)sendWeiboWithBlock:(void (^)(id obj, NSError *error))block andContent:(NSString*)content andImage:(UIImage*)image {

    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:ACCESS_TOKEN];
    
    NSDictionary *params = @{@"access_token":token,@"status":content};
    
    return [[AFAppDotNetAPIClient sharedClient] POST:@"2/statuses/upload.json" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
        [formData appendPartWithFileData:UIImagePNGRepresentation(image) name:@"pic" fileName:@"pic" mimeType:@"image/png"];
    
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (block) {
            block(responseObject,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (block) {
            block(nil,error);
        }
    }];
}

#if 0
//获取登录用户的粉丝列表
+ (NSURLSessionDataTask *)getFansLists:(void (^)(id obj, NSError *error))block {

//    https://api.weibo.com/2/friendships/followers.json
    
    NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:ACCESS_TOKEN];
    NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:UID];
    
    NSDictionary *params = @{@"access_token":token,@"uid":uid};
    
    return [[AFAppDotNetAPIClient sharedClient] GET:@"2/friendships/followers.json" parameters:params success:^(NSURLSessionDataTask *task, NSDictionary *JSON) {
        
        NSMutableArray *users = [NSMutableArray array];
        NSArray *array = JSON[@"users"];
        [array enumerateObjectsUsingBlock:^(NSDictionary *userInfo, NSUInteger idx, BOOL *stop) {
            
            User *user = [User userWithUserInfo:userInfo];
            
            [users addObject:user];
            
        }];
        
        if (block) {
            block(users,nil);
        }
        
//        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        if (block) {
            block([NSArray array],error);
        }
    
    }];
    
    
}
#endif
@end












